<?php
  defined('_VALID_MOS') or die('UnAuthorized Access');

  error_reporting(0);
  function block_param($id_img, $type, $value)
  {
    global $database;
    $objResponse = new xajaxResponse();
    if ($value)
    {
      $database->setQuery("select count(type) from #__jguard_block_list where `type`='" . $type .
        "' and `value`= '" . $value . "'");
      $count_rows = $database->loadResult();
      if ($count_rows == 0)
      {
        $database->setQuery("insert into #__jguard_block_list (`type`, `value`) values ('" . $type .
          "','" . $value . "')");
        $database->query();

        $objResponse->assign($id_img, "src", "components/com_jdefender/images/locked.gif");

      }
      else
      {
        $database->setQuery("DELETE FROM `#__jguard_block_list` WHERE `type`='" . $type .
          "' and `value`= '" . $value . "'");
        $database->query();

        $objResponse->assign($id_img, "src", "components/com_jdefender/images/unlocked.gif");

      }
    }
    return $objResponse;
  }
  function show_card($id, $log)
  {
    global $database;

    $data = getObjectList("select *,DATE_FORMAT(`ctime`, '%e-%m-%Y <small><b>%k:%i</b></small>') as ctime from #__jguard_log where `id`='" .
      $id . "'");
    $objResponse = new xajaxResponse();

    $database->setQuery("select `name` from #__users where `id`='" . $data[0]->user_id . "'");
    $login = $database->loadResult();

    $text = '<div align=left><input type="checkbox" name="delete_all_similar_ip" id="similar_ip" value="' .
      $data[0]->ip . '">
								Delete all card with similar ip</div>';
    if ($login)
    {
      $text .= '					<div align=left><input type="checkbox" name="delete_all_similar_login" id="similar_login" value="' .
        $data[0]->user_id . '">
									Delete all card with similar login</div>';
    }
    else
    {
      $text .= '					<div align=left><input type="checkbox" name="delete_without_login" id="similar_login" value="1">
									Delete all card without login</div>';
    }
    $text .= '					<input type="submit" value="Execute">';
    $objResponse->assign("div_action", "innerHTML", $text);


    $text = "<table class='info' width=100%>";
    $blocks = getObjectList("select * from #__jguard_block_list where `type`='ip' and `value`='" .
      $data[0]->ip . "'");
    $OnClick = ' onClick="document.getElementById(\'ip_img\').src=\'components/com_jdefender/images/load.gif\';xajax_block_param(\'ip_img\',\'ip\',\'' .
      $data[0]->ip . '\');" ';
    if (count($blocks) > 0)
    {
      $image = '<img alt="unblock" style="cursor: pointer;" id="ip_img" src="components/com_jdefender/images/security_f2_tick1.gif" ' .
        $OnClick . '>';
    }
    else
    {
      $image = '<img alt="block" style="cursor: pointer;" id="ip_img" src="components/com_jdefender/images/security_f2_open1.png" ' .
        $OnClick . '>';
    }
    $text .= "<tr><td align='left'> " . $data[0]->ip . "</td><td align='right'>" . $image .
      "</td></tr>";
    $text .= "</table>";
    $objResponse->assign("ip_params", "innerHTML", $text);

    $text = "<table class='info' width=100%>";
    $gets_str = (unserialize($data[0]->url));

    if ($gets_str)
    {
      //parse_str ($gets_str["query"], $gets_arr);


      //<img src="\administrator\components\com_jguard\images\security_f2_tick1.gif">
      //<img src="\administrator\components\com_jguard\images\security_f2_open1.png">
      $count_get = 0;
      foreach ($gets_str as $key => $get)
      {
        $count_get++;
        //$blocks=getObjectList("select * from #__jguard_block_list where `type`='get' and `value`='".$get."'");
        $id_img = 'img_get' . $count_get;
        $OnClick = ' onClick="document.getElementById(\'' . $id_img . '\').src=\'components/com_jdefender/images/load.gif\';xajax_block_param(\'' .
          $id_img . '\',\'get\',\'' . $get . '\');" ';
        $image = '';
        /*if(count($blocks)>0)
        {$image='<img alt="unblock" style="cursor: pointer;" id="'.$id_img.'" src="\administrator\components\com_jguard\images\security_f2_tick1.gif" '.$OnClick.'>';}
        else{$image='<img alt="block" style="cursor: pointer;" id="'.$id_img.'" src="\administrator\components\com_jguard\images\security_f2_open1.png" '.$OnClick.'>';}*/
        $text .= "<tr><td align='left'>" . $key . '=' . $get . "</td><td align='right'>" . $image .
          "</td></tr>";
      }

    }
    $text .= "</table>";
    $objResponse->assign("get_params", "innerHTML", $text);

    $text = "<table class='info' width=100%>";
    $posts_arr = unserialize($data[0]->post);
    if ($posts_arr)
    {


      //print_array($posts_arr,0, $posts );

      foreach ($posts_arr as $key => $post)
      {
        $count_post++;
        $blocks = getObjectList("select * from #__jguard_block_list where `type`='post' and `value`='" .
          $post . "'");
        $id_img = 'img_post' . $count_post;
        $OnClick = ' onClick="document.getElementById(\'' . $id_img . '\').src=\'components/com_jdefender/images/load.gif\';xajax_block_param(\'' .
          $id_img . '\',\'post\',\'' . $key . '=' . $post . '\');" ';
        $image = '';
        /*if(count($blocks)>0){$image='<img alt="unblock" style="cursor: pointer;" id="'.$id_img.'" src="\administrator\components\com_jguard\images\security_f2_tick1.gif" '.$OnClick.'>';}
        else{$image='<img alt="block" style="cursor: pointer;" id="'.$id_img.'" src="\administrator\components\com_jguard\images\security_f2_open1.png" '.$OnClick.'>';}*/
        $text .= "<tr><td align='left'>" . $key . '=' . $post . "</td><td align='right'>" . $image .
          "</td></tr>";
      }
    }
    $text .= "</table>";
    $objResponse->assign("post_params", "innerHTML", $text);


    $text = "<table class='info' width=100%>";
    if ($data[0]->referer)
    {
      $referer = $data[0]->referer;
      $OnClick = ' onClick="document.getElementById(\'img_referer\').src=\'components/com_jdefender/images/load.gif\';xajax_block_param(\'img_referer\',\'referer\',\'' .
        $referer["host"] . '\');" ';
      $blocks = getObjectList("select * from #__jguard_block_list where `type`='referer' and `value`='" .
        $referer["host"] . "'");
      if (count($blocks) > 0)
      {
        $image = '<img alt="unblock" style="cursor: pointer;" id="img_referer" src="components/com_jdefender/images/security_f2_tick1.gif" ' .
          $OnClick . '>';
      }
      else
      {
        $image = '<img alt="block" style="cursor: pointer;" id="img_referer" src="components/com_jdefender/images/security_f2_open1.png" ' .
          $OnClick . '>';
      }
      $text .= "<tr><td align='left' nowrap> <span onmouseover= \"return overlib('" . $data[0]->
        referer . "', CAPTION, 'referer', BELOW, RIGHT);\" onmouseout=\"return nd();\" >" . $data[0]->
        referer . "</span></td><td align='right'>" . $image . "</td></tr>";
    }
    $text .= "</table>";
    $objResponse->assign("referer_params", "innerHTML", $text);



    $text = "<table class='info' width=100%>";
    $database->setQuery("select `name` from #__users where `id`='" . $data[0]->user_id . "'");
    $login = $database->loadResult();
    if ($login)
    {
      $database->setQuery("select `name` from #__users where `id`='" . $data[0]->user_id . "'");
      $login = $database->loadResult();
      $OnClick = ' onClick="document.getElementById(\'img_login\').src=\'components/com_jdefender/images/load.gif\';xajax_block_param(\'img_login\',\'login\',\'' .
        $data[0]->user_id . '\');" ';
      $blocks = getObjectList("select * from #__jguard_block_list where `type`='login' and `value`='" .
        $data[0]->user_id . "'");
      if (count($blocks) > 0)
      {
        $image = '<img alt="unblock" style="cursor: pointer;" id="img_login" src="components/com_jdefender/images/security_f2_tick1.gif" ' .
          $OnClick . '>';
      }
      else
      {
        $image = '<img alt="block" style="cursor: pointer;" id="img_login" src="components/com_jdefender/images/security_f2_open1.png" ' .
          $OnClick . '>';
      }
      $text .= "<tr><td align='left'>" . $login . "</td><td align='right'>" . $image . "</td></tr>";
    }
    $text .= "</table>";
    $objResponse->assign("login_params", "innerHTML", $text);
    $objResponse->script("Effect.BlindDown('card_table_div');");
    return $objResponse;
  }
  function print_array($argument, $padding, &$ret_arr, $up_key = '')
  {
    foreach ($argument as $key => $get)
    {
      if (is_array($get))
      {
        print_array($get, $padding++, $ret_arr, $key);
      }
      else
      {
        if ($up_key)
        {
          $t_var = $up_key . '=';
        }
        else
        {
          $t_var = $key . '=';
        }

        $t_var .= $get;
        $ret_arr[] = $t_var;
      }
    }
    return $ret_arr;
  }
  function jdGetDirectoryList($folder)
  {
    if ($dir = @opendir($folder))
    {

      while ($file = readdir($dir))
      {
        if (filetype($folder . '/' . $file) == 'dir' and $file != '.' and $file != '..')
        {
          $id = md5($folder . '/' . $file);
          $name = str_replace(':', '', $folder);
          $name = str_replace('/', '_', $name);
          $name .= "_" . $file;
          $home = $file;
          if (!is_readable($folder . '/' . $file))
          {
            $list .= "\n<div id=\"$id\" align='left'><span id='$name'>" . "<a  href='#'  onClick=\"xajax_open_folder('$folder/$file','$home','$name'); \">" .
              "<img src = 'components/com_jdefender/images/plus.gif' border='0'> </a></span>" .
              "<input type='checkbox' name='folder[$id]' id='folder[$id]' value='$folder/$file'><font color='red'>  $file</font><br></div>";
          }
          else
          {
            $list .= "\n<div id=\"$id\" align='left'><span id='$name'>" . "<a  href='#'  onClick=\"xajax_open_folder('$folder/$file','$home','$name'); \">" .
              "<img src = 'components/com_jdefender/images/plus.gif' border='0'> </a></span>" .
              "<input type='checkbox' name='folder[$id]' id='folder[$id]' value='$folder/$file'>  $file<br></div>";
          }

        }

      }
      rewind($dir);
      while ($file = readdir($dir))
      {
        if (filetype($folder . '/' . $file) != 'dir' and $file != '.' and $file != '..')
        {
          $id = md5($folder . '/' . $file);
          $name = str_replace(':', '', $folder);
          $name = str_replace('/', '_', $name);
          $name .= "_" . $file;
          $home = $file;

          if (!is_readable($folder . '/' . $file))
          {
            $list .= "\n<div id=\"$id\" align='left'>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='folder[$id]' id='folder[$id]' value='$folder/$file'><font color='red'>  $file</font><br></div>";
          }
          else
          {
            $list .= "\n<div id=\"$id\" align='left'>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='folder[$id]' id='folder[$id]' value='$folder/$file'>  $file<br></div>";
          }

        }

      }
      closedir($dir);
    }
    $out = "<div style=\"padding-left:20px\">$list</div>";
    return $out;
  }



  function open_folder($folder, $home, $name = '')
  {
    $objResponse = new xajaxResponse();
    if (!is_readable($folder))
    {
      $objResponse->alert("The folder is not readable!");
      return $objResponse;

    }
    $out = jdGetDirectoryList($folder);
    $id = md5($folder);

    if ($name != '')
    {
      $objResponse->assign($name, "innerHTML", "<a href='#' onClick =\"xajax_close_folder('$folder','$home', '$name', '$id')\" ><img src = 'components/com_jdefender/images/minus.gif' border='0'> </a>");
    }

    $objResponse->append($id, "innerHTML", $out);
    return $objResponse;

  }

  function close_folder($folder, $home, $name, $id)
  {
    $objResponse = new xajaxResponse();
    //$objResponse->alert($home);
    $name = dirname($folder);
    $out = '';
    if (!is_readable($folder))
    {
      $out = "\n<div id=\"$id\" align='left'><span id='$name'><a  href='#'  onClick=\"xajax_open_folder('$folder','$home','$name');  \">" .
        "<img src = 'components/com_jdefender/images/plus.gif' border='0'> </a></span>" .
        "<input type='checkbox' name='folder[$id]' id='folder[$id]' value='$folder'><font color='red'>  $home</font></div>";
    }
    else
    {
      $out = "\n<div id=\"$id\" align='left'><span id='$name'><a  href='#'  onClick=\"xajax_open_folder('$folder','$home','$name');  \">" .
        "<img src = 'components/com_jdefender/images/plus.gif' border='0'> </a></span>" .
        "<input type='checkbox' name='folder[$id]' id='folder[$id]' value='$folder'> $home</div>";
    }



    $objResponse->assign($id, 'innerHTML', $out);
    return $objResponse;
  }

/*function select_dir($path, $name){
$objResponse = new xajaxResponse();
$fp = fopen('components/com_jdefender/tmp.txt', 'a+');
$tmp = fread($fp,1000000);
$array_rows = explode("\r\n", $tmp);
fclose($fp);
if (!in_array($path, $array_rows)){
$fp = fopen('components/com_jdefender/tmp.txt', 'a+');
fwrite($fp, $path."\r\n");
select_subdirs($path);
rewind($fp);
$array_list = explode("\r\n", fread($fp, 1000000));
$path_changed = preg_quote($path, '/');
foreach($array_list as $item){

if (preg_match("/$path_changed/", $item)){
//$id = md5($item);
$objResponse->assign($item, "innerHTML","<img src='components/com_jdefender/images/checkbox_checked.gif' border='0' onClick=\"this.src='components/com_jdefender/images/load.gif'\">");
}
}

//$objResponse->alert($path, "innerHTML", $basename);
fclose($fp);
}

else {

$tmp2 = preg_quote($path, "/");
//$tmp2 = str_replace("-","\-", $tmp2);
//$objResponse->alert(count($array_rows));
$count = count($array_rows);

for( $i=0; $i<$count;$i++){
if (preg_match("/$tmp2/", $array_rows[$i])){//$array_rows[$i] == $path
//$id = md5($array_rows[$i]);
$objResponse->assign($array_rows[$i],"innerHTML","<img src='components/com_jdefender/images/checkbox.gif' border='0' onClick=\"this.src='components/com_jdefender/images/load.gif'\">");
unset($array_rows[$i]);
}
}
rsort($array_rows);
$fp = fopen('components/com_jdefender/tmp.txt', 'w');
$tmp = implode("\r\n", $array_rows);
fwrite($fp, $tmp);
$objResponse->assign($path, "innerHTML", "<img src='components/com_jdefender/images/checkbox.gif' border='0' onClick=\"this.src='components/com_jdefender/images/load.gif'\"");
fclose($fp);

}
return $objResponse;
}*/

/*function select_subdirs($path){


if ($dir = @opendir($path)) {
$fp = fopen('components/com_jdefender/tmp.txt', 'a+');
$tmp = fread($fp,1 + filesize('components/com_jdefender/tmp.txt'));
$array_rows = explode("\r\n", $tmp);
while($file = readdir($dir) ) {
if(filetype($path.'/'.$file) == 'dir' and $file!='.' and $file!='..'){
if (!in_array($path.'/'.$file, $array_rows)){
// $objResponse->alert($path.'/'.$file);
//return $objResponse;
select_subdirs($path.'/'.$file);
fwrite($fp, $path.'/'.$file."\r\n");
} 
}
}  
closedir($dir);
}
}
*/



  function mosGetSizes($size)
  {
    if ($size < 1024)
      $size = number_format(Round($size, 3), 0, ',', '.') . " B";
    elseif ($size < 1048576)
      $size = number_format(Round($size / 1024, 3), 2, ',', '.') . " KB";
    elseif ($size < 1073741824)
      $size = number_format(Round($size / 1048576, 3), 2, ',', '.') . " MB";
    elseif (1073741824 < $size)
      $size = number_format(Round($size / 1073741824, 3), 2, ',', '.') . " GB";
    elseif (1099511627776 < $size)
      $size = number_format(Round($size / 1099511627776, 3), 2, ',', '.') . " TB";
    return $size;
  }


  function create_restoration()
  {
    global $database, $mosConfig_absolute_path;
    print $_POST[param][name];

    $todo = '';

    if ($_POST[param][dis_file] == 'true' and $_POST[param][dis_tables] != 'true')
    {
      $todo = 'tables_only';

    }
    else
      if ($_POST[param][dis_tables] == 'true' and $_POST[param][dis_file] != 'true')
      {
        $todo = 'files_only';

      }

      else
        if ($_POST[param][dis_file] != 'true' and $_POST[param][dis_tables] != 'true')
        {

          $todo = 'tables_files';


        }
        else
          if ($_POST[param][dis_file] == 'true' and $_POST[param][dis_tables] == 'true')
          {
            $todo = 'error';

          }

    if (!restore_validation())
    {
      $todo = 'error';
    }

    switch ($todo)
    {

    case 'files_only':
      if (jdCreateBackup('manual', true, false))
      {
        $message = RST_SUCCESS;
        $color = 488000;
      }

      mosRedirect("index2.php?option=com_jdefender&task=restore", $message);
      break;

    case 'tables_only':
      if (jdCreateBackup('manual', false, true))
      {
        $message = RST_SUCCESS;
        $color = 488000;
      }
      mosRedirect("index2.php?option=com_jdefender&task=restore", $message);
      break;

    case 'tables_files':
      if (jdCreateBackup('manual', true, true))
      {
        $message = RST_SUCCESS;
        $color = 488000;
      }
      mosRedirect("index2.php?option=com_jdefender&task=restore", $message);
      break;

    case 'error':
      $message = RST_FAIL;
      $color = 881100;
      mosRedirect("index2.php?option=com_jdefender&task=restore", $message);
      break;

    default:
      break;
    }


  }


  function jdCreateBackup($type, $files = false, $tables = false)
  {
    global $mosConfig_absolute_path, $database, $mosConfig_dbprefix, $mosConfig_db, $_VERSION;
    include ('includes/pcl/pclzip.lib.php');
    //print_r($array_rows);
    //print "<pre>";
    //print_r($_POST[folder]);
    //print "</pre>";

    if ($_POST[param][name] == '')
    {
      $name = time() . '_noName_' . $type;
    }
    else
    {
      $name = time() . '_' . $_POST[param][name] . '_manual';
    }
    //print $name;
    $ziparchive = new PclZip($name . '.zip');
    if ($files == true)
    {
      if ($_POST[folder][home] == '1')
      {
        if (!$ziparchive->create($mosConfig_absolute_path . "/", '', $mosConfig_absolute_path . '/'))
        {
          print "The Archive could not be Created";
        }
        /*else
        {
        print "<div align='left' style='color:red;'><pre>";
        print_r($ziparchive ->listContent());
        print "</pre></div>";
        if (copy($mosConfig_absolute_path . '/administrator/' . $name . '.zip', $mosConfig_absolute_path .
        '/administrator/backups/' . $name . '.zip'))
        {
        unlink($mosConfig_absolute_path . '/administrator/' . $name . '.zip');
        print "<h2>Status OK</h2>";
        }
        }*/
      }
      else
      {
        $fldrs = $_POST[folder];
        if (is_array($fldrs))
        {
          foreach ($fldrs as $element)
          {
            $array_rows[] = $element;

          }

          if (!$ziparchive->create($array_rows, '', $mosConfig_absolute_path . '/'))
          {
            print "The Archive could not be Created";
          }
          else
          {
            //print "<div align='left'><pre>";
            //    print_r($ziparchive ->listContent());
            //print "</pre></div>";


          }
        }
      }
    }
    if ($tables == true and count($_POST[table]) > 0)
    {
      set_magic_quotes_runtime(0);
      $tbls = $_POST[table];
      $fields = jdTableCreate($tbls);
      print " <div align='left'><pre>";
      print_r($fields);
      print "</pre></div>";
      $fp = fopen('database_backup.sql', "w");
      $comments = "/* -------JDefender Backup--------\n";
      $comments .= $_POST[comments];
      $comments .= " */\n";
      print $comments;
      fwrite($fp, $comments);
      foreach ($fields as $table_name => $fld)
      {
        if ($_POST[param][drop] == '1')
          fwrite($fp, "DROP TABLE IF EXISTS `$table_name`;/*jdSePaRaTor*/\n");
      }
      foreach ($fields as $table_name => $fld)
      {

        $auto_inc = getObjectList("SHOW TABLE STATUS FROM `" . $mosConfig_db . "` like '" . $table_name .
          "'");
        $auto_inc = number_format($auto_inc[0]->Auto_increment);


        if ($_POST[param][exist] == '1')
          fwrite($fp, str_replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS", $fld));
        else
          fwrite($fp, $fld);
        if ($_POST[param][auto] == '1')
          fwrite($fp, " AUTO_INCREMENT=$auto_inc");
        fwrite($fp, ";/*jdSePaRaTor*/\n");
        print "<div align='left'><pre>";
        print $fld . " AUTO_INCREMENT = $auto_inc;\n";
        print "</pre></div>";

        $sql = "SELECT * FROM " . str_replace($mosConfig_dbprefix, "#__", $table_name);
        $result = getAssoc($sql);
        foreach ($result as $res)
        {
          if (is_array($res))
          {
            $upper_lim = count($res);
            $counter = 1;
            $query = "INSERT INTO `$table_name` VALUES(";
            foreach ($res as $field_name => $field_value)
            {
              if ($counter == $upper_lim)
              {
                if (is_numeric($field_value))
                {
                  $query .= "$field_value";
                }
                else
                {

                  //$field_value = ereg_replace("\r\n|\n", mysql_escape_string("\r\n"), $field_value);
                  $field_value = mysql_escape_string($field_value);
                  $field_value = " '" . str_replace('\\\'', '\'\'', $field_value) . "'";
                  $query .= $field_value;
                }
              }
              else
              {
                if (is_numeric($field_value))
                {
                  $query .= "$field_value , ";
                }
                else
                {

                  //$field_value = ereg_replace("\r\n|\n", mysql_escape_string("\r\n"), $field_value);
                  $field_value = mysql_escape_string($field_value);
                  $field_value = " '" . str_replace('\\\'', '\'\'', $field_value) . "',";
                  $query .= $field_value;
                }
                $counter++;
              }
            }
            $query .= ");/*jdSePaRaTor*/\n";
            print "</br>" . $query;
            fwrite($fp, $query);
          }
        }
      }
      fclose($fp);
      if (file_exists($name . '.zip'))
      {
        $ziparchive->add($mosConfig_absolute_path . '/administrator/database_backup.sql', 'cache/', $mosConfig_absolute_path .
          '/administrator/');
      }
      else
      {
        $ziparchive->create($mosConfig_absolute_path . "/administrator/database_backup.sql", 'cache/',
          $mosConfig_absolute_path . '/administrator/');
      }
      unlink($mosConfig_absolute_path . '/administrator/database_backup.sql');
    }

    if (copy($mosConfig_absolute_path . '/administrator/' . $name . '.zip', $mosConfig_absolute_path .
      '/administrator/backups/' . $name . '.zip'))
    {
      unlink($mosConfig_absolute_path . '/administrator/' . $name . '.zip');

    }


    return true;
  }

  function array_to_vector($value)
  {
    foreach ($value as $element)
    {
      if (is_array($element) and count($element) > 0)
      {
        $result = array_merge($result, array_to_vector($element));
      }
      else
        if ($element != '')
        {

          $result[] = $element;

        }
    }
    return $result;
  }


  function restore_validation()
  {
    if (preg_match("/\\|\[|\]|\{|\}|\+|\-|\(|\)|\~|\`|\!|\@|\%|\^|\&|\*|\.|\,|\/|\?|\<|\>|\;|\:|\'|\"|\||_/",
      $_POST[param][name]))
    {
      print "<br>ERROR";
      return false;
    }

    return true;
  }

/**
 * @param array A list of table names
 * @return array A list the create SQL for the tables
 */
  function jdTableCreate($tables)
  {
    global $database;
    $result = array();

    foreach ($tables as $tblval)
    {
      $database->setQuery('SHOW CREATE table ' . $tblval);
      $database->query();
      $res = $database->loadResultArray(1);
      $result[$tblval] = $res[0];
    }

    return $result;
  }



  function getAssoc($sql)
  {
    global $database, $_VERSION;
    if ($_VERSION->PRODUCT == 'Joomla!')
    {//for Joomla
      $database->setQuery($sql);
      $result = $database->loadAssocList();
      return $result;
    }
    else
      if ($_VERSION->PRODUCT == 'Mambo')
      {//for Mambo
        $database->setQuery($sql);
        $result = $database->retrieveResults('', 0, 'assoc');
        return $result;
      }
  }

  function getObjectList($sql)
  {
    global $database, $_VERSION;
    if ($_VERSION->PRODUCT == 'Joomla!')
    {//for Joomla
      $database->setQuery($sql);
      $result = $database->loadObjectList();
      return $result;
    }
    else
      if ($_VERSION->PRODUCT == 'Mambo')
      {//for Mambo
        $database->setQuery($sql);
        $result = $database->retrieveResults('', 0, 'object');
        return $result;
      }
  }
?>